<template>
	 
		<view class="" style="width: 100vw;height: 100vh">
		<view 
	style="min-height: 100vh">
		
		<!-- <image src="/static/login/login_bg.png" mode="scaleToFill" class="user_bg"></image> -->
		<hx-navbar title=" " :back="true" :fixed="true" :color="knavTitleColor" barPlaceholder="hidden" transparent="auto"></hx-navbar>
		<!-- <image src="/static/login/log_bg.png" mode="scaleToFill" class="bg"></image> -->
		<view class="pass-title">设置新密码</view>
		<view class="input_box">
			<view class="input_boxx">
				<view class="input_panel">
					<input type="text" :password="true" class="inputer" placeholder-class="inputer_placeholder" placeholder="请输入新密码"
						v-model="newPwd" maxlength="12">
				</view>
			</view>
			<view class="input_boxx notBtm">
				<view class="input_panel">
					<input type="text" :password="true" class="inputer" placeholder-class="inputer_placeholder" placeholder="请再次输入新密码"
						v-model="rePwd" maxlength="12">
				</view>
			</view>
			<view class="pass-tip">密码内需同时包含数字、字母,长度在6-12之间</view>
			<view class="login_btn pass" @click="submitHandler()"  :style="{background:buttonBcak}">确认</view>
		</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
					selectColorSize: this.$store.state.selectColorSize, //字体
							buttonBcak: this.$store.state.buttonBcak, //按钮颜色
				newPwd: '',
				rePwd: '',
				mobile: '',
				code: '',
			}
		},
		onLoad(options) {
			this.mobile = options.mobile
			this.code = options.code
		},
		methods: {
			strRole(pass) {
				let role = /^(?=.*\d+)(?=.*[A-Za-z]+)[\w]{6,12}$/;
				return role.test(pass);
			},
			submitHandler() {
				if (this.submitStatus) return false;
				this.submitStatus = true;
				if (this.code === '') {
					this.$common.errorToShow('请输入验证码');
					this.submitStatus = false;
					return;
				}
				if (!this.strRole(this.newPwd)) {
					this.$common.errorToShow('密码内需同时包含数字、字母,长度在6-12之间');
					this.submitStatus = false;
					return;
				}
				if (this.newPwd != this.rePwd) {
					this.$common.errorToShow('两次输入的密码不一样,请重新确认');
					this.submitStatus = false;
					return;
				}
				let data = {
					mobile: this.mobile,
					code: this.code,
					newpwd: this.newPwd,
					repwd: this.rePwd
				};
				this.$api.userForgetPwd(data, res => {
					if (res.status) {
						this.submitStatus = false;
						this.$common.successToShow(res.msg,res=>{
							uni.redirectTo({
								url: '/pages/login/login'
							})
						});
						
					} else {
						this.$common.errorToShow(res.msg)
						this.submitStatus = false;
					}
				}, res => {
					this.submitStatus = false;
				});
			},
		}
	}
</script>

<style>
	@import '/pages/login/login.css';
</style>
